package com.dailyblue.example.springcloud.gateway.filter;

import com.dailyblue.example.springcloud.gateway.bean.Message;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
public class MessageGatewayFilterFactory extends AbstractGatewayFilterFactory<Message> {

    public MessageGatewayFilterFactory() {
        super(Message.class);
    }

    @Override
    public GatewayFilter apply(Message config) {
        GatewayFilter filter = (exchange, chain) -> {
            System.out.println("Hello,world!config:" + config);
            return chain.filter(exchange);
        };
        return filter;
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("first", "last");
    }
}
